<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //封装每个功能的函数,然后返回里面的promise
        function fn1(){
            return new Promise((resolve,reject)=>{
            console.log('开始获取用户姓名');
                try{
                    setTimeout(()=>{
                        console.log('获取用户姓名成功');
                        const user = {
                            name : 'chen'
                        }
                        resolve(user)
                    },1000)
                }
                catch(e){
                    reject(e.message)
                }
            })
        }
        function fn2(user){
            return new Promise((resolve,reject)=>{
            console.log('开始获取用户手机号');
                try{
                    setTimeout(()=>{
                        console.log('获取用户手机号成功');
                        const pnumber = {
                            pnumber : '1212121212'
                        }
                        resolve({...user,...pnumber})
                    },1000)
                }
                catch(e){
                    reject(e.message)
                }
            })
        }
        function fn3(pnumber){
            return new Promise((resolve,reject)=>{
            console.log('开始获取用户性别');
                try{
                    setTimeout(()=>{
                        console.log('获取用户性别成功');
                        const sex = {
                            sex : '男'
                        }
                        resolve({...pnumber,...sex})
                    },1000)
                }
                catch(e){
                    reject(e.message)
                }
            })
        }

        async function getUser(){
            const user = await fn1()
            const pnumber = await fn2(user)
            const sex = await fn3(pnumber)

            console.log('全部数据',sex);
        }

        getUser()
    </script>
</body>
</html>